namespace Example.Controllers
{
    // TODO : This needs tests
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Web.Mvc;
    using Example.Models;
    using SimpleWebServices.Web;
    using SimpleWebServices.Web.Mvc;

    [InternalServerError]
    [Allow(Methods = "GET, HEAD, OPTIONS, POST")]
    [CacheControl, ContentLanguage, ContentLocation, ContentMD5]
    [Resource("{tenant}/registration")]
    public sealed class RegistrationController : TenantController
    {
        [ContentNegotiation(".html", "*/*, text/*, text/html")]
        public ActionResult HtmlRepresentation(CultureInfo language)
        {
            return this.HtmlView(language, new RegistrationForm().Populated<RegistrationForm>().ApplyDefaultValues<RegistrationForm>());
        }

        [ContentNegotiation(".xhtml", "application/xhtml+xml")]
        public ActionResult XhtmlRepresentation(CultureInfo language)
        {
            return this.XhtmlView(language, new RegistrationForm().Populated<RegistrationForm>().ApplyDefaultValues<RegistrationForm>());
        }

        [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The derived type is necessary.")]
        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "ASP.NET MVC requires the method to be an instance member.")]
        [Post]
        public ActionResult Post(RegistrationForm model)
        {
            if (null == model)
            {
                throw new ArgumentNullException("model");
            }

            return new SeeOtherResult(HttpContextFactory.Current.Request.TenantPath() + "/registration" + HttpContextFactory.Current.Request.RawQueryString(model.Token));
        }
    }
}